package com.deltapunkt.proxy.factory;

import java.net.SocketAddress;
import java.nio.channels.SocketChannel;

import com.deltapunkt.proxy.AsyncServer;
import com.deltapunkt.proxy.Proxy;

public abstract class ProxyFactory {
	protected final SocketAddress targetAddress;

	protected ProxyFactory(SocketAddress targetAddress) {
		this.targetAddress = targetAddress;
	}

	abstract public Proxy createProxy(AsyncServer server, SocketChannel s);

	public static ProxyFactory forProxyType(ProxyType type,
			SocketAddress targetAddress) {
		ProxyFactory pf = null;
		switch (type) {
		case PORT_FORWARD:
			pf = new PortProxyFactory(targetAddress);
			break;
		case CS_AUTH_PORT_FORWARD:
			pf = new ClientAuthProxyFactory(targetAddress);
			break;
			
		case SS_AUTH_PORT_FORWARD:
			pf = new ServerAuthProxyFactory(targetAddress);
			break;

		default:
			pf = new PortProxyFactory(targetAddress);
			break;
		}

		return pf;
	}

	public static ProxyFactory forPortForward(SocketAddress targetAddress) {
		return new PortProxyFactory(targetAddress);
	}

	public static ProxyFactory forServerAuthPortForward(
			SocketAddress targetAddress) {
		return new ServerAuthProxyFactory(targetAddress);
	}

	public static ProxyFactory forClientAuthPortForward(
			SocketAddress targetAddress) {
		return new ClientAuthProxyFactory(targetAddress);
	}
}
